package com.bml.www.teacher.account.forgetpwd;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.bml.www.teacher.R;
import com.pachong.android.baseuicomponent.activity.BaseActivity;
import com.pachong.android.frameworkbase.customviews.IconTextArrowEditText;
import com.pachong.android.frameworkbase.customviews.edittext.PasswordEditText;

import butterknife.Bind;
import butterknife.OnClick;

import static com.bml.www.teacher.R.id.nextForget;
import static com.bml.www.teacher.R.id.yzPassword;

public class ForgetPwdActivity extends BaseActivity {

    @Bind(R.id.forgetPhone)
    IconTextArrowEditText mForgetPhone;
    @Bind(R.id.newPassword)
    PasswordEditText mNewPassword;
    @Bind(R.id.line_tv)
    TextView mLineTv;
    @Bind(R.id.yzPassword)
    IconTextArrowEditText mYzPassword;
    @Bind(R.id.send_yz)
    TextView mSendYz;
    @Bind(R.id.nextForget)
    Button mNextForget;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initToolBar();
    }

    public static void start(Activity activity) {
        Intent intent = new Intent(activity, ForgetPwdActivity.class);
        activity.startActivity(intent);
    }

    private void initToolBar() {
        getCustomToolbar().setBackgroundColor(Color.parseColor("#ffffff"));
        getCustomToolbar().setTitle("找回密码");
        //设置左边返回键
        getCustomToolbar().addLeftImageButton(getResources().getDrawable(R.mipmap.backby), new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            finish();
            }
        });
    }

    @Override
    public View createDataView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.activity_forget_pwd, null);
    }

    @OnClick({R.id.send_yz, nextForget})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.send_yz:
                MyCountDownTimer mc = new MyCountDownTimer(60000, 1000);
                mc.start();
                break;
            case nextForget:
                yzPassword();
                break;
        }
    }

    private void yzPassword() {



        FindSuccessActivity.start(ForgetPwdActivity.this);

    }


    /**
     * 继承 CountDownTimer 防范
     * <p>
     * 重写 父类的方法 onTick() 、 onFinish()
     */
    class MyCountDownTimer extends CountDownTimer {
        /**
         * @param millisInFuture    表示以毫秒为单位 倒计时的总数
         *                          <p>
         *                          例如 millisInFuture=1000 表示1秒
         * @param countDownInterval 表示 间隔 多少微秒 调用一次 onTick 方法
         *                          <p>
         *                          例如: countDownInterval =1000 ; 表示每1000毫秒调用一次onTick()
         */
        public MyCountDownTimer(long millisInFuture, long countDownInterval) {
            super(millisInFuture, countDownInterval);
        }

        @Override
        public void onFinish() {
            mSendYz.setText("重新获取");
        }

        @Override
        public void onTick(long millisUntilFinished) {
            Log.i("MainActivity", millisUntilFinished + "");
            if (mSendYz != null) {
                mSendYz.setText(millisUntilFinished / 1000 + "s");
            }

        }
    }

}
